package LC;

import java.util.Scanner;

/**
 * https://leetcode.com/problems/integer-to-roman/description/
 * Given an integer, convert it to a roman numeral.
 * Input is guaranteed to be within the range from 1 to 3999.
 */
public class LC_012_IntegerToRoman_String {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            System.out.println(intToRoman(n));
        }
        sc.close();
    }

    private static String intToRoman(int num) {
        String[][] roman = {
                {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
                {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
                {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
                {"", "M", "MM", "MMM"}
        };

        StringBuilder ret = new StringBuilder();
        int digit = 0;
        while (num != 0) {
            int remain = num % 10;
            ret.insert(0, roman[digit][remain]);
            digit++;
            num /= 10;
        }

        return ret.toString();
    }
}



